package com.zatech.cgnci.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zatech.cgnci.project.base.utils.ConvertUtils;
import com.zatech.cgnci.project.base.utils.VerifyUtils;
import com.zatech.cgnci.project.entity.CgnciAccessoryDO;
import com.zatech.cgnci.project.entity.CgnciBusinessStatDO;
import com.zatech.cgnci.project.entity.CgnciUnderwritingPolicyDO;
import com.zatech.cgnci.project.mapper.CgnciBusinessStatMapper;
import com.zatech.cgnci.project.service.CgnciBusinessStatService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zatech.cgnci.project.vo.CgnciAccessoryVO;
import com.zatech.cgnci.project.vo.CgnciBusinessStatVO;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 承保统计表 服务实现类
 * </p>
 *
 * @author Generator
 * @since 2025-05-19
 */
@Service
public class CgnciBusinessStatServiceImpl extends ServiceImpl<CgnciBusinessStatMapper, CgnciBusinessStatDO> implements CgnciBusinessStatService {

    @Override
    public List<CgnciBusinessStatVO> listBusinessStatBusinessId(Long businessId) {
        List<CgnciBusinessStatDO> statList = this.list(new LambdaQueryWrapper<CgnciBusinessStatDO>()
                .eq(CgnciBusinessStatDO::getBusinessId, businessId));
        return ConvertUtils.convert(statList, CgnciBusinessStatVO.class);
    }

    @Override
    public void deleteBusinessStat(Long businessId, String riskSubTypeCode) {
        // 查询统计字段
        CgnciBusinessStatDO statDO = this.getOne(new LambdaQueryWrapper<CgnciBusinessStatDO>()
                .eq(CgnciBusinessStatDO::getBusinessId, businessId)
                .eq(CgnciBusinessStatDO::getRiskSubTypeCode, riskSubTypeCode)
        );
        if (VerifyUtils.isNotEmpty(statDO)) {
            this.removeById(statDO.getStatId());
        }
    }
}
